﻿// <copyright file="MovieReviewsPage.xaml.cs" company="Microsoft Corporation">
// Copyright (c) 2009 Microsoft Corporation All Rights Reserved
// </copyright>
// <author>Michael S. Scherotter</author>
// <email>mischero@microsoft.com</email>
// <date>2009-04-08</date>
// <summary>Movie Reviews Test Page</summary>

namespace DemoNYTimes
{
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Media.Imaging;
    using NYTimes;
    
    /// <summary>
    /// The Movie review test page
    /// </summary>
    public partial class MovieReviewsPage : UserControl
    {
        /// <summary>
        /// Initializes a new instance of the MovieReviewsPage class
        /// </summary>
        public MovieReviewsPage()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Image failed event handler
        /// </summary>
        /// <param name="sender">the image with the failure</param>
        /// <param name="e">the exception routed event arguments</param>
        private void OnImageFailed(object sender, ExceptionRoutedEventArgs e)
        {
            var image = sender as Image;

            var source = image.Source as BitmapImage;

            System.Diagnostics.Debug.WriteLine("Image error with {0}: {1}", source.UriSource, e.ErrorException.Message);
        }

        /// <summary>
        /// Trigger the query if the user presses the return button
        /// </summary>
        /// <param name="sender">the textbox</param>
        /// <param name="e">the key event arguments</param>
        private void OnQueryKeyDown(object sender, System.Windows.Input.KeyEventArgs e)
        {
            if (e.Key == System.Windows.Input.Key.Enter)
            {
                var textBox = sender as TextBox;

                var movieReviews = this.Resources["MovieReviews"] as MovieReviewsByKeyword;

                movieReviews.Query = textBox.Text;
            }
        }
    }
}
